<template>
  <div class="template1">
    <div class="leftNav">
      <el-tree :data="data" :props="defaultProps" @node-click="handleNodeClick"></el-tree>
      <!-- <el-button type="text" size="small" @click="addSP('addF')">添加参数</el-button>
      <el-button type="text" size="small" class="del" @click="del">删除参数</el-button> -->
    </div>
    <div class="subject" :style="'width:84%;height:'+(height+120)+'px;padding-bottom: 0px;padding-top: 60px;'">
      <div class="head" id="head1">
        <div class="tit">
            {{actData.code}}
          <span class="add" @click="addSP('add')">添加参数</span>
        </div>
      </div>
      <el-main style="height:100% !important">
          <SPList></SPList>
      </el-main>
    </div>
    <addSP></addSP>
  </div>
</template>
<script>
import SPList from "./SPList.vue"
import addSP from "./addSP.vue"
import { request } from "../../assets/request.js";
export default {
  data() {
    return {
      data: [],
      defaultProps: {
        children: "children",
        label: "label"
      },
      height: "",
      formInline: {
        user: "",
        region: ""
      },
      actData:''
    };
  },
  created(){
    this.selectList()
    
  },
  methods: {
    handleNodeClick(data) {
      console.log(data)
      this.actData=data;
      this.$root.$emit("handleNodeClick", this.actData);
    },
    resetForm(formName) {
      this.$refs[formName].resetFields();
    },
    onSubmit() {
      console.log("submit!");
    },
    addSP(type){
        this.$root.$emit("addSP",type,this.actData);
    },
    del(){
      let row=this.actData
      let that=this
      request.delAlert({
          name:'删除该参数',
          that,
          fn(obj){
              let url='constant/'+row.id+'?greenToken='+request.greenToken
              request.ajaxDel({
                url,
                that,
                fn(res){
                  that.$message(obj)
                  that.selectList()
                }
              })
          }
      })
    },
    selectList(obj) {
        let url = "constant";
        let that=this   //解决this指向问题
        request.ajaxGet({
            url,
            that,
            params:obj,
            fn(res){ 
                let large=res.list
                for(let i in large){
                  large[i].label=large[i].code
                }
                that.actData=large[0]
                that.$root.$emit("handleNodeClick", that.actData);
                that.data=large
            }
        })
    }
  },
  mounted() {
    let height = `${document.documentElement.clientHeight}`; 
    this.height = parseInt(height) - 182;
  },
  components:{
      SPList,   //系统参数列表
      addSP,
  }
};
</script>
<style scoped lang="less">
    @import "../template1.less";
</style>
<style lang="less" scoped>
.template1{
  .el-tree-node__content{
    height:36px !important;
  }
  .del{
    bottom: 40px !important;
    left: -5px;
  }
  .el-button+.el-button{
    margin-left: 0px !important;
  }
}
</style>

